using namespace std;

#include "Side.h"
#include "Wall.h"
#include "Door.h"
#include "Room.h"
#include "Roomplan.h"

int main() {
	const size_t ROOMWIDTH = 9;  // defines the Height for every Room in the Roomplan
	const size_t ROOMHEIGHT = 7; // defines the Width for every Room in the Roomplan

	Roomplan rp(ROOMWIDTH, ROOMHEIGHT);  // create a new Roomplan instance

	// Allocate some Sides	
	Side *sTop = new Wall(rp.getWidth());
	Side *sRight = new Door(rp.getHeight());
	Side *sBottom = new Wall(rp.getWidth());
	Side *sLeft = new Wall(rp.getHeight());

	// Allocate a new Wall and test the member functions
	Wall *w = new Wall();
	std::cout << "Default color of a wall: " << w->getColor() << std::endl;
	w->setColor("#ABCDEF");
	std::cout << "Color after setColor: " << w->getColor() << std::endl;

	// Allocate a Door and test the member functions
	Door *d = new Door();
	std::cout << "By default a door is ";
	if (d->isOpenend())
		std::cout << "opened!!" << std::endl;
	else
		std::cout << "closed!!" << std::endl;
	d->setOpened(true);

	// *w and *d mustn't be deleted (freed) because the room does this

	// Instantiate some Rooms
	Room r(sTop, sRight, sBottom, sLeft);
	Room r2(new Wall(rp.getWidth()),new Wall(rp.getWidth()),new Wall(rp.getWidth()),new Wall(rp.getWidth()));
	Room r3(r);
	Room *r4 = new Room(new Wall(), new Door(), new Wall(), new Wall());
	Room r5(new Door(), d, new Door(), w);
	
	// The following doesn't work:
	// Door d;
	// Side *s = &d;
	// Room r(s, new Wall(), new Wall(), new Wall());
	// 
	// because the destructor of the Room tries to free 
	// its sides

	// Add the rooms (order matters !)
	size_t room0 = rp.addRoom(r);
	rp.addRoom(r2);
	rp.addRoom(r3);
	rp.addRoom(*r4);
	rp.addRoom(r5);

	// show that the roomplan has a copy of the room
	delete r4;  

	// connect some rooms
	rp.connectToNext(0);
	rp.connectToNext(1);
	rp.connectToNext(4);  // does nothing because it's the last room

	// Print some single rooms
	std::cout << "==== Room 1 ====" << std::endl;
	rp.getRoom(room0)->Print();
	
	std::cout << std::endl << "==== Room 3 ====" << std::endl;
	rp.getRoom(2)->Print();
	
	// Print the roomplan
	std::cout << std::endl << "==== Roomplan ====" << std::endl;
	rp.Print();

	return 0;
}